﻿/* $Author: alexander@bsrgin.ru $
 * $Id: AlarmApplication.java 8 2011-11-13 20:11:06Z alexander@bsrgin.ru $
 * 
 * Описание класса приложения
 */
package ru.habrahabr.prettyalarm;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Vibrator;

public class AlarmApplication extends Application
{
	private static AlarmApplication singleton;
	private Vibrator vibe = null;
	
	@Override
	public void onCreate()
	{
		super.onCreate();
		singleton = this;
		
		vibe = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE) ;
	}
	
	public static AlarmApplication getInstance()
	{
		return singleton;
	}
	
	public static String getApplicationVersion()
	{
		try {
			return getInstance().getApplicationContext().getPackageManager().getPackageInfo("ru.habrahabr.prettyalarm", 0).versionName;
		} catch (NameNotFoundException e) {
			return "App not installed!";
		}
	}
	
	public static void vibrate()
	{
		if (getInstance().vibe == null) return;
		getInstance().vibe.vibrate(20); // ms
	}
}
